/*! Texture and Render Target interface implementation for Direct3D 11

@author Sergio J. de los Santos
*/
#ifndef __CRUSH_RENDERDEVICE_DIRECT3D11_TEXTURE_HEADER__
#define __CRUSH_RENDERDEVICE_DIRECT3D11_TEXTURE_HEADER__

using namespace std;

struct UpdateInfo
{
	uint32	x, y, z;
	uint32	width, height, depth;
	uint32	slice, mipmap;

	UpdateInfo():x(0), y(0), z(0), width(0), height(0), depth(0), slice(0), mipmap(0){}
};

//-----------------------------------------------------------------------------
//-| Desc: 
//-|	   
//-----------------------------------------------------------------------------
class TextureD3D11 
{
protected: // Attributos Basicos de Win32
	ID3D11Device*					m_pd3dDevice;
	ID3D11Resource*					m_pd3dTexture;
	ID3D11ShaderResourceView*		m_pd3dResourceView; 
	DXGI_FORMAT						m_dxgiFormat;
	D3D11_TEXTURE2D_DESC			m_texDescriptor;
	D3D11_SHADER_RESOURCE_VIEW_DESC	m_srViewDesc;	// Desc del Shader Resource (para texture binding)

protected: // Metodos

	bool CreateTextureArray();
public:
	// Constructores
	TextureD3D11(ID3D11Device* pd3dDevice);
	// Destructor
	~TextureD3D11();

	const D3D11_TEXTURE2D_DESC&	GetDescriptor() const	{ return m_texDescriptor;			}

	//! Create for render targets & dynamic textures
	bool Create(const D3D11_TEXTURE2D_DESC& texInfo);

	//! Create From File
	bool CreateFromFile(const string& strFileName);
	
	//! Create From Raw
	bool CreateFromRAW(const D3D11_TEXTURE2D_DESC& texInfo, void* pData);

	// Update the content of a dynamic texture. Buffer is a DDS (not raw Data
	bool UpdateFromFile(ID3D11DeviceContext* pd3dContext, const UpdateInfo& ui, void* pBuffer, uint32 size);

	bool LoadTextureOnArray(ID3D11DeviceContext* pd3dContext, int slice, const string& filename);

	void Destroy();

	ID3D11Resource*						GetTextureResource()	{ return m_pd3dTexture;			}
	ID3D11ShaderResourceView*			GetResourceView()		{ return m_pd3dResourceView;	}
	FORCEINLINE const DXGI_FORMAT&		GetFormat() const		{ return m_dxgiFormat;			}

};

#endif

